loginer = App.get("loginer");
console.log(loginer);

// 城市替换
$.getJSON("/json/city_list.json", function(result) {
	App.set("$Cache_city_list", result);
	App.set("$Cache_city_city_list", App.get("$Cache_city_list")[0].sub);
});
App.set("$Event.change_city_province", function() {
	var province = this.value;
	if (province) {
		App.set("$Cache_city_city_list", App.get("$Cache_city_list")[province].sub);
		App.set("$Cache_city_type", App.get("$Cache_city_list")[province].type)
	};
});

App.set("$Event.change_city_city", function() {
	var city = this.value;
	// console.log($(this).find("option:selected").text())
	if (App.get("$Cache_city_type") && city) {
		App.set("$Cache_city_city_area_list", App.get("$Cache_city_city_list")[city].sub);
	};
});
//开启修改
App.set("$Event.unlock_change_info", function() {
	App.model.toggle("$Cache_unlock_change_info");
});

// 更换头像
App.set("$Event.file_btn_click", function() {
	$("#logofile").click();
});
App.set("$Event.user_logo_change", function() {
	var logo_dir = fileupload(this)
	loginer.logo = logo_dir;
	App.set("loginer.logo", logo_dir);
	$.cookie("loginer", loginer);
	var info = {
		sid: App.get("loginer.sid"),
		logo: logo_dir
	};
	change_info(info);
	console.log(logo_dir);
});

App.set("$Event.save_change_info", function() {
	var info = {};
	if (App.get("$Cache_nickname")) {
		info.nickname = App.get("$Cache_nickname");
	};
	if (App.get("$Cache_phone")) {
		info.phone = App.get("$Cache_phone");
	};
	if (App.get("$Cache_email")) {
		info.email = App.get("$Cache_email");
	};
	if (App.get("$Cache_sex")) {
		info.sex = App.get("$Cache_sex");
	};
	if (App.get("$Cache_education")) {
		info.education = App.get("$Cache_education");
	};
	info.address = {
		province: $("[name='province']").find("option:selected").text(),
		city: $("[name='city']").find("option:selected").text(),
		area: $("[name='area']").find("option:selected").text()
	};
	info.address = JSON.stringify(info.address);
	info.sid = App.get("loginer.sid");;
	change_info(info);
	App.model.toggle("$Cache_unlock_change_info");
})

// 定义修改信息
function change_info(info) {
	$.ajax({
		url: "/api/complex/MyInfo",
		type: "put",
		data: info,
		success: function(result) {
			alert("修改成功!");
			var new_loginer = $.extend({}, loginer, info);
			console.log(new_loginer);
			App.set("loginer", new_loginer);
			if (info.address) {
				App.set("loginer.address", eval("(" + new_loginer.address + ")"))
			};
			$.cookie("loginer", JSON.stringify(App.get('loginer')));
		},
		error: function(e) {
			alert("网络错误，请稍后修改");
		}
	})
}